package com.pay.cloud;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;

import androidx.core.app.ActivityCompat;

public class DeviceUtils {

    public static String sn(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (activity.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(
                        activity, new String[]{Manifest.permission.READ_PHONE_STATE}, 10);
            }
            return android.os.Build.getSerial();
        } else {
            return Build.SERIAL;
        }
    }

    public static String appVersion(Context context) {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packInfo = null;
        try {
            packInfo = packageManager.getPackageInfo(context.getPackageName(),0);
        } catch (PackageManager.NameNotFoundException e) {

        }
        if (null != packInfo) {
            return packInfo.versionName;
        }
        return "";
    }
}
